import { useState } from "react";
import styles from "../happle/PosterSection.module.css";

// 导入图片
import img1 from "../mucces/images/mess1.jpg";
import img2 from "../mucces/images/mess2.jpg";
import img3 from "../mucces/images/mess3.jpg";
import img4 from "../mucces/images/mess4.jpg";
import img5 from "../mucces/images/mess5.jpg";
import img6 from "../mucces/images/mess6.jpg";
import img7 from "../mucces/images/mess7.jpg";
import img8 from "../mucces/images/mess8.jpg";

// 数据类型定义
interface Festival {
  id: string;
  name: string;
  isHot: boolean;
  templates: Template[];
}

interface Template {
  type: string;
  count: number;
  imageUrl: string;
}

// 模拟数据
const festivals: Festival[] = [
  {
    id: "dragon",
    name: "配乐上新",
    isHot: true,
    templates: [
      {
        type: "大气钢琴配乐",
        count: 106,
        imageUrl: img1,
      },
      {
        type: "优雅提琴配乐",
        count: 117,
        imageUrl: img2,
      },
      {
        type: "节奏打击乐",
        count: 76,
        imageUrl: img3,
      },
      {
        type: "悠扬古筝配乐",
        count: 74,
        imageUrl: img4,
      },
      {
        type: "萨克斯配乐",
        count: 110,
        imageUrl: img5,
      },
      {
        type: "旋律吉他配乐",
        count: 102,
        imageUrl: img6,
      },
      {
        type: "尤克里里配乐",
        count: 92,
        imageUrl: img7,
      },
      {
        type: "合成器配乐",
        count: 117,
        imageUrl: img8,
      },
    ],
  },
  {
    id: "children",
    name: "精选听单",
    isHot: true,
    templates: [
      {
        type: "影视转场音效",
        count: 60,
        imageUrl: img3,
      },
      {
        type: "党政庆典配乐",
        count: 40,
        imageUrl: img4,
      },
      {
        type: "温馨浪漫配乐",
        count: 114,
        imageUrl: img5,
      },
      {
        type: "购物促销配乐",
        count: 52,
        imageUrl: img6,
      },
      {
        type: "自然宣传片配乐",
        count: 60,
        imageUrl: img1,
      },
      {
        type: "动感国潮风配乐",
        count: 60,
        imageUrl: img7,
      },
      {
        type: "史诗磅礴配乐",
        count: 40,
        imageUrl: img2,
      },
      {
        type: "现场发布会",
        count: 120,
        imageUrl: img8,
      },
    ],
  },
  {
    id: "summer",
    name: "热门场景",
    isHot: false,
    templates: [
      {
        type: "叙事朗读场景配乐",
        count: 48,
        imageUrl: img2,
      },
      {
        type: "影视片头配乐",
        count: 118,
        imageUrl: img3,
      },
      {
        type: "品牌宣传",
        count: 94,
        imageUrl: img4,
      },
      {
        type: "婚礼告白",
        count: 80,
        imageUrl: img5,
      },
      {
        type: "活动剪辑配乐",
        count: 100,
        imageUrl: img7,
      },
       {
        type: "运动健身配乐",
        count: 72,
        imageUrl: img8,
      },
       {
        type: "清新旅拍配乐",
        count: 80,
        imageUrl: img6,
      },
       {
        type: "新闻采访配乐",
        count: 43,
        imageUrl: img1,
      },
    ],
  },
  {
    id: "grain",
    name: "常用情绪",
    isHot: false,
    templates: [
      {
        type: "励志进取",
        count: 80,
        imageUrl: img4,
      },
      {
        type: "喜悦欢乐",
        count: 84,
        imageUrl: img5,
      },
      {
        type: "紧张急促",
        count: 81,
        imageUrl: img7,
      },
      {
        type: "希望乐观",
        count: 92,
        imageUrl: img8,
      },
      {
        type: "忧郁悲伤",
        count: 76,
        imageUrl: img1,
      },
      {
        type: "温情感人",
        count: 60,
        imageUrl: img2,
      },
      {
        type: "安静冥想",
        count: 60,
        imageUrl: img3,
      },
      {
        type: "诡异阴森",
        count: 47,
        imageUrl: img6,
      },
    ],
  }
];

export default function MarketingCalendar() {
  const [selectedFestival, setSelectedFestival] = useState<Festival>(
    festivals[0]
  );
  const [lockSelection, setLockSelection] = useState(false);
  const handleHover = (festival: Festival) => {
    if (!lockSelection) {
      setSelectedFestival(festival);
    }
  };
  const handleClick = (festival: Festival) => {
    setSelectedFestival(festival);
    setLockSelection(true);
  };

  return (
    <div className={styles.container}>
      <div className={styles.headerRow}>
        <h2 className={styles.sectionTitle}>行业趋势-配乐篇</h2>
        <p className={styles.sectionDesc}>精选热点专题实时更新,热门素材轻松get~</p>
        <div className={styles.festivalList}>
          {festivals.map((festival) => (
            <div
              key={festival.id}
              className={`${styles.festivalItem} ${
                selectedFestival.id === festival.id ? styles.active : ""
              }`}
              onMouseEnter={() => handleHover(festival)}
              onMouseLeave={() => setLockSelection(false)}
              onClick={() => handleClick(festival)}
            >
              <div className={styles.festivalLeft}>
                <span className={styles.festivalName}>{festival.name}</span>
              </div>
            </div>
          ))}
        </div>
      </div>

      <div className={styles.templateGallery}>
        {selectedFestival.templates.map((template) => (
          <div key={template.type} className={styles.templateCard}>
            <div className={styles.templateContent}>
              <div className={styles.templateImageContainer}>
                <img
                  src={template.imageUrl}
                  alt={template.type}
                  className={styles.templateImage}
                />
              </div>
              <div className={styles.templateInfo}>
                <h4>{template.type}</h4>
                <span>共{template.count}个作品</span>
              </div>
            </div>
          </div>
        ))}
      </div>
    </div>
  );
}